<!DOCTYPE html>
<?php session_start(); ?>
<html>
	<head>
		<title>ShowBooks</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<link href="index.css" type="text/css" rel="stylesheet" media="screen" />
		<link href="css/showbook.css" type="text/css" rel="stylesheet" media="screen" />
		<script src="js/showBook.js" type="text/javascript"></script>
		<script src="js/validator.js" type="text/javascript"></script>
		<script type="text/javascript" >
			function checkTag()
			{
				var content = document.getElementsByName("newtag")[0];
				if (validator.notEmpty.check(content.value))
				{
					if (validator.noSpecialSymbols.check(content.value))
					{
						return true;
					}
					else
						{
							alert(validator.noSpecialSymbols.message);
							return false;
						}
					}
				else
					{
						alert("不能添加空标签");
						return false;
					}
			}
			
			function checkComment()
			{
				var content = document.getElementsByName("commentContent")[0];
				if (validator.notEmpty.check(content.value))
				{
					if (validator.noSpecialSymbols.check(content.value))
					{
						return true;
					}
					else
						{
							alert(validator.noSpecialSymbols.message);
							return false;
						}
					}
				else
					{
						alert("评论内容不能为空");
						return false;
					}
				}
			</script>
	</head>
	<body>
		<?php
		if(!isset($_SESSION["session_username"]))
		{
			header("location:RegisterSite.php");
			exit();
		}
		$logname = $_SESSION["session_username"];
		?>
		<div class="topbar">
			<div class="loginfo">
				<ul>
					<li>
						<?=$logname?>
						<?php
							if(isset($_SESSION["session_admin"]) && $_SESSION["session_admin"] == true)
							{
						?>
							<input type="button" value="用户管理" onclick="window.location.href ='UserControl.php'"/>
						<?php
							}
                        ?>
						<input type="button" value="注销" onclick="window.location.href ='Logout.php'"/>
					</li>
				</ul>
			</div>
			<div class="globalitems">
				<ul>
					<li>
						<a href="index.php">首页</a>
					</li>
					<li>
						<a href="SearchBook.php?allbook=true">书库</a>
					</li>
					<li>
						<a href="showGroup.php">我的群组</a>
						</li>
						<li>
							<a href="index.php">随便看看</a>
						</li>
					</ul>
				</div>
			</div>
			<div id="main">
				<?php
				$name = $_REQUEST["bookname"];
				include_once 'Book.php';
				$book = Book::findBookByName($name);
				$pic = $book->getFace();
				$intro = $book->getIntro();
				$bkVote = $book->getTop();
				$bkDeVote = $book->getDown();
				$bkTag = $book->getTag();
				?>
					<div id="bookface">
						<img width="200" height="300" src="<?=$pic?>"/>
						<div>
							<input type="button" value="喜欢" onclick="bookUp('<?=$name ?>')"/><span id="bookup"><?=$bkVote?></span>
							<input type="button" value="不喜欢" onclick="bookDown('<?=$name ?>')"/><span id="bookdown"><?=$bkDeVote?></span>
						</div>
					</div>
					<fieldset id="tags">
						<legend>图书标签</legend>
						<div>				
									<?php
									for($count = 0; $count<count($bkTag);$count++)
									{
										?>
										<span class="tag"><?=$bkTag[$count]?></span>
										<?php
									}
									?>
						</div>


							<div id="addtag">
								<form action="AddTag.php" method="post"  onsubmit="return checkTag()">
										<span id="tagtitle">添加标签:</span>
											<span class="input">
												<input type="text" name="newtag"/>
											</span>
											<input type="hidden" name="tagBkname" value="<?=$name?>"/>
										<div>
											<input id="ad" type="submit" value="添加"/>
										</div>
								</form>
							</div>
							<?php
							if(isset($_SESSION["session_admin"]) && $_SESSION["session_admin"] == true)
							{
								?>
								<form action="ClearTag.php" method="post">
									<input type="hidden" name="cletagBkname" value="<?=$name?>"/>
									<input type="submit" value="清空标签" />
								</form>
								<?php
							}
							?>

					</fieldset>
<div class="clearfix"></div>
						<div id="introduce">
							<fieldset>
								<legend>图书简介···</legend>
							<p><?=$intro?></p>
						</fieldset>
						</div>


					<div id="discuss">
					    <p id="discuss_title">全部评论：</p>
							<?php
							include_once "Comment.php";
							$comlist = Comment::getCommentsByBook($name);
							for($count = 0;$count < count($comlist);$count ++)
							{
								$comUser = $comlist[$count]->getUserName();
								$comContent = $comlist[$count]->getContent();
								$comTime = $comlist[$count]->getTime();
								$comVote = $comlist[$count]->getVote();
								$comDeVote = $comlist[$count]->getDevote();
								$comId = $comlist[$count]->getId();
								?>
								<div class="commentblock">
									<div class="commenttitle"><span class="user"><?=$comUser?></span><span class="time"><?=$comTime?></span></div>
									<p><?=$comContent?></p>
									<div class="support">
									<input type="button" value="顶"/ onclick="commentUp(<?=$comId ?>)"><span id="<?=$comId ?>up"><?=$comVote ?></span>
									<input type="button" value="踩"/ onclick="commentDown(<?=$comId ?>)"><span id="<?=$comId ?>down"><?=$comDeVote ?></span>
									<?php
								if(isset($_SESSION["session_admin"]) && $_SESSION["session_admin"] == true)
								{
									?>
									<form action="DeleteComment.php" method="post">
										<input type="hidden" name="delcomid" value="<?=$comId?>"/>
										<input type="hidden" name="delcomBkname" value="<?=$name?>"/>
										<input type="submit" value="删除评论" />
									</form>
									<?php
								}
								?>
								</div>
								<div class="clearfix"></div>
								</div>
								<?php
							}
							?>
							<div id="addcomment">
								<form action="AddComment.php" method="post" onsubmit="return checkComment()">
									<fieldset id="commentEdit">
										<legend><span id="comtitle">我要评论:</span></legend>
										<div>
											<span class="input">
												<textarea name="commentContent"></textarea>
											</span>
											<input type="hidden" name="commentBkname" value="<?=$name?>"/>
										</div>
										<div>
											<input id="po" type="submit" value="发表" />
										</div>
									</fieldset>
								</form>
							</div>
					</div>
			</div>
	</body>
</html>